gapminder_file <- "https://raw.githubusercontent.com/COMBINE-Australia/RNAseq-R/gh-pages/data/gapminder-FiveYearData.csv"
download.file(gapminder_file, destfile="gapminder-FiveYearData.csv")
library("ggplot2")
gapminder <- read.csv("gapminder-FiveYearData.csv")
ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp))

ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp)) + geom_point()

ggplot(data = gapminder, aes(x = year, y = lifeExp)) + geom_point()

ggplot(data = gapminder, aes(x = year, y = lifeExp, color=continent)) +
geom_point()

ggplot(data = gapminder, aes(x=year, y=lifeExp, by=country, color=continent)) +
geom_line()

ggplot(data = gapminder, aes(x=year, y=lifeExp, by=country, color=continent)) +
geom_line() + geom_point()

ggplot(data = gapminder, aes(x=year, y=lifeExp, by=country)) +
geom_line(aes(color=continent)) + geom_point()

ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp, color=continent)) + geom_point()

ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp, color=continent)) + geom_point(alpha = 0.1) + scale_x_log10() + facet_wrap(~continent)

ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_point() + scale_x_log10() + geom_smooth(method="lm")

ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp)) +
geom_point(color="orange", size=4) + scale_x_log10() + geom_smooth(method="lm", size=0.5)

ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp, color = continent)) +
geom_point(size=3, shape=17) + scale_x_log10() +
geom_smooth(method="lm", size=1.5)

starts.with <- substr(gapminder$country, start = 1, stop = 1)
az.countries <- gapminder[starts.with %in% c("C", "U"), ]
ggplot(data = az.countries, aes(x = year, y = lifeExp, color=continent)) + geom_line() + facet_wrap( ~ country)

ggplot(data = az.countries, aes(x = year, y = lifeExp, color=continent)) +
geom_line() + facet_wrap( ~ country) +
labs(
x = "Year", # x axis title
y = "Life expectancy", # y axis title
title = "Figure 1", # main title of figure
color = "Continent" # title of legend
) +
theme(axis.text.x=element_blank(), axis.ticks.x=element_blank())

ggplot(data = gapminder, aes(x = gdpPercap, fill=continent)) +
geom_density(alpha=0.6) + facet_wrap( ~ year) + scale_x_log10()
